﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.Reflection;
using System.Web;


namespace MaxLeaf.CallWebService_OverNight
{
    public partial class frmOverNight : Form
    {
        public frmOverNight()
        {
            InitializeComponent();
        }

        private void btnCondition_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("轮询程序启动！", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                timer1.Start(); 
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            timer1.Stop(); 
            MessageBox.Show("轮询程序关闭！", "", MessageBoxButtons.OK, MessageBoxIcon.Information); 
            this.Close(); 
        }



        private void CallWebServices()
        {
            string strDBName = "Web1";
            try
            {
                strDBName = "WS1";                
                ServiceReference1.MaxLeafWebServiceSoapClient tads = new ServiceReference1.MaxLeafWebServiceSoapClient("WS1");
                tads.CheckWebLog(strDBName);

                strDBName = "WS2";
                ServiceReference1.MaxLeafWebServiceSoapClient tads2 = new ServiceReference1.MaxLeafWebServiceSoapClient("WS2");
                tads2.CheckWebLog(strDBName);

                strDBName = "WS3";
                ServiceReference1.MaxLeafWebServiceSoapClient tads3 = new ServiceReference1.MaxLeafWebServiceSoapClient("WS3");
                tads3.CheckWebLog(strDBName);
            }
            catch (Exception ex)
            {               
                if (!File.Exists(@"C:\maxLeaf\WebK3\" + strDBName + "_" + strDBName + ".txt"))
                {
                    File.CreateText(@"C:\maxLeaf\WebK3\" + strDBName + "_" + strDBName + ".txt");
                }
                File.WriteAllText(@"C:\maxLeaf\WebK3\" + strDBName + "_" + strDBName + ".txt", ex.ToString());
            } 
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            CallWebServices();
        }
      
    }
}
